package com.delphi.tcde.plug.views;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;

public class GraphView extends ViewPart {

    private Action load;
    private Action run;
    private TableViewer viewer;
    
    public GraphView() {
        // TODO Auto-generated constructor stub
    }

    @Override
    public void createPartControl(Composite parent) {
        viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
        contributeToActionBars();
        makeActions();
        // TODO Auto-generated method stub

    }

    @Override
    public void setFocus() {
        // TODO Auto-generated method stub

    }
    
    private void makeActions() {
        load = new Action() {
                public void run() {
                        showMessage("Action 1 executed");
                }
        };
        load.setText("Load graph");
        load.setToolTipText("Loading graph from file");
        load.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
                getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
        
        run = new Action() {
                public void run() {
                        showMessage("Action 2 executed");
                }
        };
        run.setText("Run algorithm");
        run.setToolTipText("Running");
        run.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
                        getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));

        };
        
        private void showMessage(String message) {
            MessageDialog.openInformation(
                    viewer.getControl().getShell(),
                    "Resource Manager View",
                    message);
        }
        
        private void fillLocalPullDown(IMenuManager manager) {
            manager.add(run);
            manager.add(new Separator());
            manager.add(load);
        }
        
        private void contributeToActionBars() {
            IActionBars bars = getViewSite().getActionBars();
            fillLocalToolBar(bars.getToolBarManager());
            fillLocalPullDown(bars.getMenuManager());
        }   
        
        private void fillLocalToolBar(IToolBarManager manager) {
            manager.add(load);
            manager.add(run);
        }
}